package com.atmaowei.service.impl;

import com.atmaowei.controller.request.BaseRequest;
import com.atmaowei.entity.Department;
import com.atmaowei.entity.Sct;
import com.atmaowei.mapper.SctMapper;
import com.atmaowei.service.SctService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SctServiceImpl implements SctService {

    @Autowired
    private SctMapper sctMapper;

    @Override
    public void delete(String sno, String cno, String tno) {
        sctMapper.delete(sno,cno,tno);
    }

    @Override
    public PageInfo<Sct> page(BaseRequest baseRequest) {
        PageHelper.startPage(baseRequest.getPageNum(), baseRequest.getPageSize());
        List<Sct> list = sctMapper.page(baseRequest);
        for (Sct sct : list) {
            sct.setSname(getSnameBySno(sct.getSno()));
            sct.setCname(getCnameByCno(sct.getCno()));
            sct.setTname(getTnameByTno(sct.getTno()));
        }
        PageInfo<Sct> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public String getSnameBySno(String sno) {
        return sctMapper.getSnameBySno(sno);
    }

    @Override
    public String getCnameByCno(String cno) {
        return sctMapper.getCnameByCno(cno);
    }

    @Override
    public String getTnameByTno(String tno) {
        return sctMapper.getTnameByTno(tno);
    }

    @Override
    public void deleteSelected(List<Sct> scts) {
        for (Sct sct : scts) {
            sctMapper.deleteSelected(sct.getSno(),sct.getCno(),sct.getTno());
        }
    }
}
